package com.ti.winona.ui;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.taplinker.client.R;
import com.ti.winona.ui.fragment.MenuLeftFragment;
import com.ti.winona.util.FragmentOperateUtil;
import com.ti.winona.util.QuitOperateUtil;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;

public class BaseSlidingFragmentActivity extends SlidingFragmentActivity {
	private MenuLeftFragment mMenuLeftFragment;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setBehindContentView(R.layout.menu_frame);
		
		// 设置left菜单
		if( savedInstanceState == null ) {
			FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
			mMenuLeftFragment = new MenuLeftFragment();
			ft.replace(R.id.menu_frame, mMenuLeftFragment);
			ft.commit();
		}else{
			mMenuLeftFragment = (MenuLeftFragment)getSupportFragmentManager().findFragmentById(R.id.menu_frame);
		}
		
		// 自定义SlidingMenu
		SlidingMenu sm = getSlidingMenu();
		sm.setShadowWidthRes(R.dimen.shadow_width);
		sm.setShadowDrawable(R.drawable.shadow);
		sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
		sm.setFadeDegree(0.35f);
		sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		
	}
	
	@Override
	public void onBackPressed() {
		if( getSupportFragmentManager().getBackStackEntryCount() > 2 ) {
			FragmentOperateUtil.popFragmentBackStack(getSupportFragmentManager());
		}else{
			// 连续点击两次退出程序
			QuitOperateUtil.quitProgram(BaseSlidingFragmentActivity.this);
		}
	}
	
}
